<!DOCTYPE html><html><head><meta charset=utf-8><title>H3DU.Meshes</title></head><body><h1> H3DU.Meshes</h1><p><a href='index.html'>Back to documentation index.</a></p><a name='H3DU.Meshes'></a>
<h3> H3DU.Meshes()</h3>Contains methods that create meshes
of various geometric shapes and solids.<p>
Note that wherever a method in this class describes how texture
coordinates are generated, it is assumed that the coordinate (0,0)
is at the lower-left corner of the texture and (1,1) is at the upper-right
corner.<h3> Methods</h3><ul><li><a href='#H3DU.Meshes.createBox'>createBox</a><br>Creates a mesh of a box (rectangular prism), which
will be centered at the origin.<li><a href='#H3DU.Meshes.createCapsule'>createCapsule</a><br>Creates a mesh of a capsule, centered at the origin.<li><a href='#H3DU.Meshes.createClosedCylinder'>createClosedCylinder</a><br>Creates a mesh of a closed cylinder.<li><a href='#H3DU.Meshes.createConvexHull'>createConvexHull</a><br>Generates the convex hull of a set of points, that is, the smallest convex set
that contains all the points given.<li><a href='#H3DU.Meshes.createCylinder'>createCylinder</a><br>Creates a mesh of a cylinder.<li><a href='#H3DU.Meshes.createDisk'>createDisk</a><br>Creates a mesh of a 2D disk.<li><a href='#H3DU.Meshes.createLathe'>createLathe</a><br>Creates a mesh of a figure generated by revolving a path of 2-dimensional
points about the Z axis.<li><a href='#H3DU.Meshes.createPartialDisk'>createPartialDisk</a><br>Creates a mesh of a 2D disk or an arc of a 2D disk.<li><a href='#H3DU.Meshes.createPlane'>createPlane</a><br>Creates a mesh of a 2D rectangle, centered at the origin.<li><a href='#H3DU.Meshes.createPointedStar'>createPointedStar</a><br>Creates a mesh in the form of a two-dimensional n-pointed star.<li><a href='#H3DU.Meshes.createSphere'>createSphere</a><br>Creates a mesh of a sphere, centered at the origin.<li><a href='#H3DU.Meshes.createTorus'>createTorus</a><br>Creates a mesh of a torus (donut), centered at the origin.</ul><a name='H3DU.Meshes.createBox'></a>
<h3> (static) H3DU.Meshes.createBox(xSize, ySize, zSize, [inward])</h3>Creates a mesh of a box (rectangular prism), which
will be centered at the origin.
See the "<a href="tutorial-shapes.html">Creating Shapes</a>" tutorial.
Will create texture coordinates such that the same texture
is used on each face of the box. The resulting mesh buffer
will use 36 vertex indices divided into 12 triangles, with each
face using two triangles. The faces will be ordered as follows:
Negative X face, positive X face, negative Y face,
positive Y face, negative Z face, positive Z face.<h4> Parameters</h4><ul><li><code>xSize</code> (Type: number)<br>Width of the box.<li><code>ySize</code> (Type: number)<br>Height of the box.<li><code>zSize</code> (Type: number)<br>Depth of the box.<li><code>inward</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point inward; otherwise, outward. Should normally be false unless the box will be viewed from the inside.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createCapsule'></a>
<h3> (static) H3DU.Meshes.createCapsule([radius], [length], [slices], [stacks], [middleStacks], [flat], [inside])</h3>Creates a mesh of a capsule, centered at the origin.
The length of the capsule will run along the Z axis. (If the capsule
has a high length and a very low radius, it will resemble a 3D line
with rounded corners.)<p>
Will also generate texture coordinates such that the V (vertical)
coordinates start from the bottom of the texture and increase from the negative
to positive Z axis, and the U (horizontal) coordinates start from the left of the
texture and increase from the positive X to positive Y to negative X to negative
Y to positive X axis.<p>
If the "length" parameter is 0, the X, Y, and Z coordinates of a point on the solid
are as described in <a href="H3DU.Meshes.html#H3DU.Meshes.createSphere">H3DU.Meshes.createSphere</a>.
See the "<a href="tutorial-shapes.html">Creating Shapes</a>" tutorial.<h4> Parameters</h4><ul><li><code>radius</code> (Type: number) (optional)<br>Radius of each spherical end of the capsule. May be null or omitted, in which case the default is 1.<li><code>length</code> (Type: number) (optional)<br>Length of the middle section. May be null or omitted, in which case the default is 1. If this value is 0, an approximation to a sphere will be generated.<li><code>slices</code> (Type: number) (optional)<br>Number of vertical sections the capsule consists of. This function will create an octahedron if "slices" is 4 and "stacks" is 2. Must be 3 or greater. May be null or omitted, in which case the default is 16.<li><code>stacks</code> (Type: number) (optional)<br>Number of horizontal sections each spherical half consists of. May be null or omitted, in which case the default is 8.<li><code>middleStacks</code> (Type: number) (optional)<br>Number of vertical sections the middle of the capsule consists of. May be null or omitted, in which case the default is 1.<li><code>flat</code> (Type: Boolean) (optional)<br>If true, will generate normals such that the capsule will be flat shaded; otherwise, will generate normals such that the capsule will be smooth shaded.<li><code>inside</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point inward; otherwise, outward. Should normally be false unless the capsule will be viewed from the inside.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createClosedCylinder'></a>
<h3> (static) H3DU.Meshes.createClosedCylinder(baseRad, topRad, height, slices, stacks, [flat], [inside])</h3>Creates a mesh of a closed cylinder. The cylinder's base will
be centered at the origin and its height will run along the
positive Z axis. The base and top will be included in the mesh if
their radius is greater than 0. Will generate texture coordinates for
the cylinder and for the base and top.
The base's and top's texture coordinates will be such that the
texture will be flat as seen from either.<p>
See <a href="H3DU.Meshes.html#H3DU.Meshes.createCylinder">H3DU.Meshes.createCylinder</a> for information on how texture
coordinates for the cylinder (other than the base and top) are generated and how
to find the coordinates of a particular point on the cylinder.<p>
See the "<a href="tutorial-shapes.html">Creating Shapes</a>" tutorial.<h4> Parameters</h4><ul><li><code>baseRad</code> (Type: number)<br>Radius of the base of the cylinder. See <a href="H3DU.Meshes.html#H3DU.Meshes.createCylinder">H3DU.Meshes.createCylinder</a>.<li><code>topRad</code> (Type: number)<br>Radius of the top of the cylinder. See <a href="H3DU.Meshes.html#H3DU.Meshes.createCylinder">H3DU.Meshes.createCylinder</a>.<li><code>height</code> (Type: number)<br>Height of the cylinder.<li><code>slices</code> (Type: number)<br>Number of lengthwise "slices" the cylinder consists of. See <a href="H3DU.Meshes.html#H3DU.Meshes.createCylinder">H3DU.Meshes.createCylinder</a>.<li><code>stacks</code> (Type: number)<br>Number of vertical stacks the cylinder consists of. May be null or omitted, in which case the default is 1.<li><code>flat</code> (Type: Boolean) (optional)<br>If true, will generate normals such that the cylinder will be flat shaded; otherwise, will generate normals such that the cylinder will be smooth shaded.<li><code>inside</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point inward; otherwise, outward. Should normally be false unless the cylinder will be viewed from the inside.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<h4> Example</h4><p>The following method creates a cone that's closed at its base.
<img src="mesh1.png"></p><pre>
function createClosedCone(radius,height,slices) {
return H3DU.Meshes.createClosedCylinder(radius,0,height,slices,1);
}</pre><a name='H3DU.Meshes.createConvexHull'></a>
<h3> (static) H3DU.Meshes.createConvexHull(points, [flat], [inside])</h3>Generates the convex hull of a set of points, that is, the smallest convex set
that contains all the points given.
<p>To use this method, you must include the script "extras/convex.js". Example:<pre>
&lt;script type="text/javascript" src="extras/convex.js">&lt;/script></pre><h4> Parameters</h4><ul><li><code>points</code> (Type: Array.&lt;number>)<br>An array of 3-element vectors each identifying a 3-dimensional point.<li><code>flat</code> (Type: Boolean) (optional)<br>If true, will generate normals such that the figure will be flat shaded; otherwise, will generate normals such that the figure will be smooth shaded.<li><code>inside</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point inward; otherwise, outward. Should normally be false unless the figure will be viewed from the inside.</ul><h4> Return Value</h4>The generated convex hull. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createCylinder'></a>
<h3> (static) H3DU.Meshes.createCylinder(baseRad, topRad, height, [slices], [stacks], [flat], [inside])</h3>Creates a mesh of a cylinder. The cylinder's base will
be centered at the origin and its height will run along the
positive Z axis. The base and top themselves will not be
included in the mesh.<p>
Texture coordinates for the cylinder (other than the base) will
be generated such that the V (vertical)
coordinates start from the bottom of the texture and increase from the origin
to the positive Z axis, and the U (horizontal) coordinates start from the left of the
texture and increase from the positive X to positive Y to negative X to negative
Y to positive X axis.<p>
The X, Y, and Z coordinates of a point on the cylinder are
<code>(-R*cos(&lambda;), -R*sin(&lambda;), H*&phi;)</code>,
where &phi; = <code>(&pi;/2 + L)/&pi;</code>, L is the latitude in radians,
&lambda; is the longitude in radians, H = <code>height</code>,
R = <code>baseRad + (topRad - baseRad) * &phi;</code>,
and west and south latitudes and
longitudes are negative. (The formula for converting latitude
and longitude is mentioned here because their meaning depends on
exactly how the texture coordinates are generated on the cylinder.
It assumes that in the texture, longitudes range from -180&deg; to 0&deg; to 180&deg; from
left to right, and latitudes range from 90&deg; to 0&deg; to -90&deg; from top to bottom.)<p>
See the "<a href="tutorial-shapes.html">Creating Shapes</a>" tutorial.<h4> Parameters</h4><ul><li><code>baseRad</code> (Type: number)<br>Radius of the base of the cylinder. If 0, this function will create an approximation to a downward pointing cone.<li><code>topRad</code> (Type: number)<br>Radius of the top of the cylinder. If 0, this function will create an approximation to an upward pointing cone.<li><code>height</code> (Type: number)<br>Height of the cylinder.<li><code>slices</code> (Type: number) (optional)<br>Number of lengthwise "slices" the cylinder consists of, each slice going through the center of the cylinder. This function will create a triangular prism if "slices" is 3 and both radiuses are the same; a triangular pyramid if "slices" is 3 and either radius is zero; a rectangular prism if "slices" is 4 and both radiuses are the same; and a rectangular pyramid if "slices" is 4 and either radius is zero. Must be 3 or greater. May be null or omitted, in which case the default is 32.<li><code>stacks</code> (Type: number) (optional)<br>Number of vertical stacks the cylinder consists of. May be null or omitted, in which case the default is 1.<li><code>flat</code> (Type: Boolean) (optional)<br>If true, will generate normals such that the cylinder will be flat shaded; otherwise, will generate normals such that the cylinder will be smooth shaded.<li><code>inside</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point inward; otherwise, outward. Should normally be false unless the cylinder will be viewed from the inside.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createDisk'></a>
<h3> (static) H3DU.Meshes.createDisk(inner, outer, [slices], [loops], [inward])</h3>Creates a mesh of a 2D disk.
Assuming the Y axis points up, the X axis right,
and the Z axis toward the viewer, the first vertex in the outer edge
of the 2D disk will be at the 12 o'clock position.
Will also generate texture coordinates.
See the "<a href="tutorial-shapes.html">Creating Shapes</a>" tutorial.<h4> Parameters</h4><ul><li><code>inner</code> (Type: number)<br>Radius of the hole in the middle of the disk. If 0, no hole is created and the method will generate a regular polygon with n sides, where n is the value of "slices". For example, if "inner" is 0 and "slices" is 3, the result will be an equilateral triangle; a square for 4 "slices", a regular pentagon for 5 "slices", and so on.<li><code>outer</code> (Type: number)<br>Outer radius of the disk.<li><code>slices</code> (Type: number) (optional)<br>Number of slices going around the disk. May be null or omitted; default is 16.<li><code>loops</code> (Type: number) (optional)<br>Number of concentric rings the disk makes up. May be null or omitted; default is 1.<li><code>inward</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point in the opposite direction of the positive Z axis; otherwise, in the same direction of the positive Z axis. Default is false.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createLathe'></a>
<h3> (static) H3DU.Meshes.createLathe(points, [slices], [flat], [inside])</h3>Creates a mesh of a figure generated by revolving a path of 2-dimensional
points about the Z axis.<p>
Texture coordinates will
be generated such that the V (vertical)
coordinates start from the bottom of the texture and increase along the Z axis in the direction
of the given path, and the U (horizontal) coordinates start from the left of the
texture and increase from the positive X to positive Y to negative X to negative
Y to positive X axis.<p><h4> Parameters</h4><ul><li><code>points</code> (Type: Array.&lt;number>)<br>Array of alternating X and Z coordinates describing a two-dimensional path that will revolve around the Z axis to generate the figure (the first number is an X coordinate, the second is a Z coordinate, and so on). Each Z coordinate is a Z coordinate of the point where the path lies, and each X coordinate is the radius of the figure at that point. The Z coordinates should be given in increasing order and should not be the same from one point to the next. This parameter's length must be 4 or greater and be an even number.<li><code>slices</code> (Type: number) (optional)<br>Number of lengthwise "slices" the figure consists of. Must be 3 or greater. May be null or omitted; default is 32.<li><code>flat</code> (Type: Boolean) (optional)<br>If true, will generate normals such that the figure will be flat shaded; otherwise, will generate normals such that the figure will be smooth shaded.<li><code>inside</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point inward; otherwise, outward. Should normally be false unless the figure will be viewed from the inside.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createPartialDisk'></a>
<h3> (static) H3DU.Meshes.createPartialDisk(inner, outer, [slices], [loops], [start], [sweep], [inward])</h3>Creates a mesh of a 2D disk or an arc of a 2D disk.
Will also generate texture coordinates.
See the "<a href="tutorial-shapes.html">Creating Shapes</a>" tutorial.<h4> Parameters</h4><ul><li><code>inner</code> (Type: number)<br>Radius of the hole where the middle of the complete disk would be. If 0, no hole is created.<li><code>outer</code> (Type: number)<br>Outer radius of the disk.<li><code>slices</code> (Type: number) (optional)<br>Number of slices going around the partial disk. May be null or omitted; default is 32.<li><code>loops</code> (Type: number) (optional)<br>Number of concentric rings the partial disk makes up. May be null or omitted; default is 1.<li><code>start</code> (Type: number) (optional)<br>Starting angle of the partial disk, in degrees. May be null or omitted; default is 0. 0 degrees is at the positive Y axis, and 90 degrees at the positive X axis. Assuming the Y axis points up, the X axis right, and the Z axis toward the viewer, 0 degrees is at the 12 o'clock position, and 90 degrees at the 3 o'clock position.<li><code>sweep</code> (Type: number) (optional)<br>Arc length of the partial disk, in degrees. May be null or omitted; default is 360. May be negative.<li><code>inward</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point in the opposite direction of the positive Z axis; otherwise, in the same direction of the positive Z axis. Default is false.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createPlane'></a>
<h3> (static) H3DU.Meshes.createPlane([width], [height], [widthDiv], [heightDiv], [inward])</h3>Creates a mesh of a 2D rectangle, centered at the origin.
The plane's Z coordinate will be 0.
Will also generate texture coordinates that increase toward
the positive X and Y axes. The texture coordinates will range
from 0 to 1 on each end of the 2D rectangle.
See the "<a href="tutorial-shapes.html">Creating Shapes</a>" tutorial.<h4> Parameters</h4><ul><li><code>width</code> (Type: number) (optional)<br>Width of the rectangle. May be null or omitted; default is 1.<li><code>height</code> (Type: number) (optional)<br>Height of the rectangle. May be null or omitted; default is 1.<li><code>widthDiv</code> (Type: number) (optional)<br>Number of horizontal subdivisions. May be null or omitted; default is 1.<li><code>heightDiv</code> (Type: number) (optional)<br>Number of vertical subdivisions. May be null or omitted; default is 1.<li><code>inward</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point in the opposite direction of the positive Z axis; otherwise, in the same direction of the positive Z axis. Default is false.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createPointedStar'></a>
<h3> (static) H3DU.Meshes.createPointedStar(points, firstRadius, secondRadius, [inward])</h3>Creates a mesh in the form of a two-dimensional n-pointed star.
Will also generate texture coordinates.<h4> Parameters</h4><ul><li><code>points</code> (Type: number)<br>Number of points in the star. Must be 2 or greater.<li><code>firstRadius</code> (Type: number)<br>First radius of the star. Must be 0 or greater; this parameter and secondRadius can't both be 0.<li><code>secondRadius</code> (Type: number)<br>Second radius of the star. Must be 0 or greater; this parameter and firstRadius can't both be 0.<li><code>inward</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point in the opposite direction of the positive Z axis; otherwise, in the same direction of the positive Z axis. Default is false.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createSphere'></a>
<h3> (static) H3DU.Meshes.createSphere([radius], [slices], [stacks], [flat], [inside])</h3>Creates a mesh of a sphere, centered at the origin.<p>
Will also generate texture coordinates such that the V (vertical)
coordinates start from the bottom of the texture and increase from the negative
to positive Z axis, and the U (horizontal) coordinates start from the left of the
texture and increase from the positive X to positive Y to negative X to negative
Y to positive X axis.<p>
The X, Y, and Z coordinates of a point on the sphere are
<code>(-R*cos(&delta;)*cos(&lambda;), -R*cos(&delta;)*sin(&lambda;), R*sin(&delta;))</code>,
where &delta; and &lambda; are the latitude and longitude, respectively, in radians, R is the sphere's radius,
and west and south latitudes and
longitudes are negative. (The formula for converting latitude
and longitude is mentioned here because their meaning depends on
exactly how the texture coordinates are generated on the sphere.
It assumes that in the texture, longitudes range from -180&deg; to 0&deg; to 180&deg; from
left to right, and latitudes range from 90&deg; to 0&deg; to -90&deg; from top to bottom.)<p>
See the "<a href="tutorial-shapes.html">Creating Shapes</a>" tutorial.<h4> Parameters</h4><ul><li><code>radius</code> (Type: number) (optional)<br>Radius of the sphere. May be null or omitted, in which case the default is 1.<li><code>slices</code> (Type: number) (optional)<br>Number of vertical sections the sphere consists of. This function will create an octahedron if "slices" is 4 and "stacks" is 2. Must be 3 or greater. May be null or omitted, in which case the default is 16.<li><code>stacks</code> (Type: number) (optional)<br>Number of horizontal sections the sphere consists of. May be null or omitted, in which case the default is 16.<li><code>flat</code> (Type: Boolean) (optional)<br>If true, will generate normals such that the sphere will be flat shaded; otherwise, will generate normals such that the sphere will be smooth shaded.<li><code>inside</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point inward; otherwise, outward. Should normally be false unless the sphere will be viewed from the inside.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<a name='H3DU.Meshes.createTorus'></a>
<h3> (static) H3DU.Meshes.createTorus(inner, outer, [lengthwise], [crosswise], [flat], [inward])</h3>Creates a mesh of a torus (donut), centered at the origin.
Will also generate texture coordinates.
See the "<a href="tutorial-shapes.html">Creating Shapes</a>" tutorial.<h4> Parameters</h4><ul><li><code>inner</code> (Type: number)<br>Inner radius (thickness) of the torus.<li><code>outer</code> (Type: number)<br>Outer radius of the torus (distance from the center to the innermost part of the torus).<li><code>lengthwise</code> (Type: number) (optional)<br>Number of lengthwise subdivisions. May be null or omitted; default is 16.<li><code>crosswise</code> (Type: number) (optional)<br>Number of crosswise subdivisions. May be null or omitted; default is 16.<li><code>flat</code> (Type: Boolean) (optional)<br>If true, will generate normals such that the torus will be flat shaded; otherwise, will generate normals such that it will be smooth shaded.<li><code>inward</code> (Type: Boolean) (optional)<br>If true, the normals generated by this method will point inward; otherwise, outward. Default is false.</ul><h4> Return Value</h4>The generated mesh. (Type: <a href="H3DU.MeshBuffer.html">H3DU.MeshBuffer</a>)<p><a href='index.html'>Back to documentation index.</a></p></body></html>
